using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using UniversityManagerWebSite.Models;
using UniversityManagerWebSite.Models.Validation;
using Services;
using IServices;
using GestionLinqLibData;

namespace UniversityManagerWebSite.Controllers
{
    public class MatiereController : Controller
    {
        private IMatiereService _service;

        public MatiereController()
        {
            _service = new MatiereService(new ModelStateWrapper(this.ModelState));

        }

        public MatiereController(IMatiereService service)
        {
            _service = service;
        }
        //
        // GET: /Matiere/

        public ActionResult Index()
        {
            return View(_service.ListMatieres().ToList());
        }

        //
        // GET: /Matiere/Details/5

        public ActionResult Delete(int id)
        {
            return View(_service.GetMatiere(id));
        }


        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Delete(matiere matiereToDelete)
        {
            if (_service.DeleteMatiere(matiereToDelete))
                return RedirectToAction("Index");

            return View(matiereToDelete);
        }

        //
        // GET: /Matiere/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Matiere/Create

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([Bind(Exclude = "id_matiere")] matiere matiereToCreate)
        {
            if (_service.CreateMatiere(matiereToCreate))
                return RedirectToAction("Index");
            return View();
        }

        //
        // GET: /Matiere/Edit/5

        public ActionResult Edit(int id)
        {
            return View(_service.GetMatiere(id));
        }

        //
        // POST: /Matiere/Edit/5

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(matiere matiereToEdit)
        {
            if (_service.EditMatiere(matiereToEdit))
                return RedirectToAction("Index");
            return View(matiereToEdit);
        }

      
    }
}
